from fastapi import APIRouter, Depends
from sqlmodel import Session
from ...core.database import get_session
from ...schemas.permission import UserCreate,UserResponse
from ...models.permission import User

from ...crud.permission import create_user,get_user


router = APIRouter(prefix="/users", tags=["用户管理"])

@router.post("/", response_model=UserResponse)
async def user_create(user:UserCreate,session: Session = Depends(get_session)):
    db_user = create_user(session, user)
    db_user = UserResponse.from_orm(db_user)
    return db_user

@router.get("/{user_id}", response_model=UserResponse)
async def user_get(user_id:int,session: Session = Depends(get_session)):
    db_user = get_user(session, user_id)
    db_user = UserResponse.from_orm(db_user)
    return db_user